﻿@{
    ViewBag.Title = "CommonSQLMangement";
    Layout = "~/Views/Shared/_GridCommonLayout.cshtml";
}







<!--begin grid code-->


<section id="widget-grid" class="">
    <div class="row">


	      
		  
        <!--Operation-->
        <div class="heading-buttons">
          

           <div class="col-xs-12 col-sm-7 col-md-7 col-lg-4">
		<h1 class="page-title txt-color-blueDark"><i class="fa fa-desktop fa-fw "></i> 
			通用SQL语句管理
			
		</h1>
	</div>
            <div class="buttons pull-right">

                
                
                <button type="button" class="btn btn-success btn-labeled "
                    data-bind="click: $root.showAddBefore"><span class="btn-label"><i class="glyphicon glyphicon-plus"></i>
                    </span>添加SQL</button>

                <button type="button" class="btn btn-primary btn-labeled "
                    data-bind="click: $root.onDataDeleting"><span class="btn-label"><i class="glyphicon glyphicon-remove"></i>
                    </span>批量删除</button>

                
            </div>
            <div style="clear: both;">
            </div>
        </div>
        <!--/Operation-->
        
      


	<!--Search-->
	<div class="filter-bar">
		<form id="formSearch">
			<div class="lbl glyphicons search" style="cursor: pointer;" data-bind="click: $root.search">
                    <i></i>筛选
                </div>
		   
		
							<div><label>ID：</label><div class='input-append'><input id='txtbSrId'  name='txtbSrId' type='text' placeholder='ID' class='input-mini' style='width: 120px;' /></div></div> 
                            <div><label>sql的名称：</label><div class='input-append'><input id='txtbSrSSqlName'  name='txtbSrSSqlName' type='text' placeholder='sql的名称' class='input-mini' style='width: 120px;' /></div></div> 
			<div class="clearfix">
			</div>
		</form>
	</div>
	<!--/search-->

	
	
    <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12 sortable-grid ui-sortable">
            <div id="wid-id-0" class="jarviswidget jarviswidget-color-darken jarviswidget-sortable" data-widget-editbutton="false">
                <header>
                    <span class="widget-icon"><i class="fa fa-table"></i></span>
                    <h2>SqlQuery</h2>
                </header>
                <div style="margin-top:35px;">
                    <div class="jarviswidget-editbox"></div>
                    <div class="widget-body no-padding">
                        <div role="grid" id="providerGrid" class="dataTables_wrapper form-inline">
                            <div class="table-responsive">

                                <div class="dt-wrapper" style="overflow-y: auto;">
                                    <table class="table table-striped table-bordered table-hover checkboxs">
                                        <!--table head-->
                                        <thead>
                                            <tr>
                                                <th style="width: 1%">
                                                    <input type="checkbox" value="0" />
                                                </th>
                                                <!-- ko foreach: headers -->
                                                <th class="center ">
                                                    <a href="#" data-bind="text: displayText@*, click: $root.sort*@" style="color: black"></a>
                                                    <i class="icon-circle-arrow-up" data-bind="    visible: value == $root.orderBy() && $root.isAsc()"></i>
                                                    <i class="icon-circle-arrow-down" data-bind="    visible: value == $root.orderBy() && !$root.isAsc()"></i>
                                                </th>
                                                <!-- /ko -->
                                                
                                                <th class="center" style="width: 60px">操作
                                                </th>
                                            </tr>
                                        </thead>
                                        <!--/table head-->
                                        <!--table body(Provider list)-->
                                        <tbody data-bind="foreach: recordSet">
                                            <tr class="selectable" onclick="">
                                                <td class="center">
                                                    <input type="checkbox" name="userSelector" data-bind="value: Id" />
                                                    <input type="hidden" data-bind="value: Id, attr: { id: Id }" />
                                                </td>
                                                
							<td class='center'><strong data-bind='text: Id'></strong></td>
<td class='left'><strong data-bind='text: SSqlName'></strong></td>
<td class='left'><strong data-bind='text: SSqlStr'></strong></td>
<td class='center'><strong data-bind='text: SUserName'></strong></td>
<td class='center'><strong data-bind='text: Tms.formatDate(DCreate)'></strong></td>
@*<td class='center'><strong data-bind='text: ISort'></strong></td>*@

							
							<td class="center">
                                                    <a href="#" class="btn-action glyphicons pencil btn-success" data-bind="click: $root.showUpdateModal">
                                                        <i></i></a>
                                                </td>
                                            </tr>
                                        </tbody>
                                        <!--/table body( Provider list)-->

                                    </table>

                                </div>
                                  
                              
							  
                                <!-- 分页 -->
                                <ul class="pagination pagination-alt">
                                    <li>
                                        <a data-bind="click: firstPage"><i class="fa fa-fast-backward "></i></a>
                                    </li>
                                    <li>
                                        <a data-bind="click: prevPage"><i class="fa  fa-backward  "></i></a>
                                    </li>
                                    <li>
                                        <a>
                                            <input id="toPage" type="text" data-bind="value: pageIndex, event: { change: $root.changePageIndex }" style="width: 25px;" />
                                            /共<span data-bind="html: totalPages"></span>页 
                                        </a>
                                    </li>
                                    <li>
                                        <a data-bind="click: nextPage"><i class="fa fa-forward "></i></a>
                                    </li>
                                    <li>
                                        <a data-bind="click: lastPage"><i class="fa fa-fast-forward "></i></a>
                                    </li>
                                </ul>

                                <div class="dt-top-row total  ">
                                    当前记录共：<span data-bind="html: totalCount"></span>条
                                </div>
                                <!--end 分页-->
                            </div>

                            <!-- /分页 -->
							  
							  
                                </div>

                                <!-- /分页 -->




                            </div>
                        </div>

                    </div>
               
        
		
	
	</article>	

     </div><!--end row-->
</section>

<input  id="HiddenUserID" type="hidden" value="@ViewBag.UserID"/>
<!--SqlQuery详细对话框-->
<div id="SqlQueryMessageModal" class="modal fade" id="ProviderMessageModal"  tabindex="-1" role="dialog"
    aria-labelledby="SqlQueryMessageModalLabel" aria-hidden="true">
	<div class="modal-content">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
            ×</button>
        <h3>SQL语句信息详细
        </h3>
    </div>
	
    <div class="modal-body">
	 <input type='hidden' id='txtbID' name='txtbID' /> 
        <form class="form-horizontal" id="formSqlQuery" data-bind="with: NodeValue">
            
						@*<span style='color: Red'>*</span>*@<div class='control-group'><label class='control-label'>sql的名称:</label><div class='controls'><input type='text' id='txtbSSqlName' name='txtbSSqlName' placeholder='sql的名称' class='span10' data-bind='value:SSqlName'/> 
</div>        </div>  
<div class='control-group'><label class='control-label'>SQL语句:</label><div class='controls'><input type='text' id='txtbSSqlStr' name='txtbSSqlStr' placeholder='SQL语句' class='span10' data-bind='value:SSqlStr'/> 
</div>        </div>  
@*<div class='control-group'><label class='control-label'>建立ID:</label><div class='controls'><input type='text' id='txtbICreateId' name='txtbICreateId' placeholder='建立ID' class='span10' data-bind='value:ICreateId'/> 
</div>        </div>  *@
@*<div class='control-group'><label class='control-label'>创建修改时间:</label><div class='controls'><input type='text' id='txtbDCreate' name='txtbDCreate' placeholder='创建修改时间' class='span10' data-bind='value:Tms.formatDate( DCreate)'/> 
</div>        </div> *@ 
@*<div class='control-group'><label class='control-label'>排序号:</label><div class='controls'><input type='text' id='txtbISort' name='txtbISort' placeholder='排序号' class='span10' data-bind='value:ISort'/> 
</div>        </div> *@ 

        </form>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">
            取消</button>
         <button id="btnSaveOrUpdateModel" class="btn btn-primary" aria-hidden="true" data-bind=" click: onDataAddingOrUpdate">
            确定</button>
    </div>
	</div><!--end div content-->
	</div>
<!--/详细SqlQuery对话框-->




<script type="text/javascript">

    var gdViewModel;
    $(function () {
        $._messengerDefaults = {
            extraClasses: 'messenger-fixed messenger-theme-future messenger-on-bottom messenger-on-right'
        }; //默认提示位置;


        var options = {

            dialogId: "SqlQueryMessageModal", //添加对话框

            pageSize: 20, //分页大小
            hidId: $("#txtbID"),
            SaveUpdateBtn: $("#btnSaveOrUpdateModel"),
            frmElement: $("#formSqlQuery"),

            //节点数据
            NodeValue: ko.observable({

                Id: 0,
                SSqlName: '',
                SSqlStr: '',
                ICreateId: 0,
                SUserName:'',
                DCreate: new Date(),
                ISort: 0,


            }),


            //用户列表Grid头部列名称
            headers: [


 { displayText: 'ID', value: 'Id', width: 'auto' },
 { displayText: 'sql的名称', value: 'SSqlName', width: 'auto' },
 { displayText: 'SQL语句', value: 'SSqlStr', width: 'auto' },
 { displayText: '建立者姓名', value: 'ICreateId', width: 'auto' },
 { displayText: '创建修改时间', value: 'DCreate', width: 'auto' },
 //{ displayText: '排序号', value: 'ISort', width: 'auto' }


            ],

            //默认的排序方式
            defaultOrderBy: "Id",
            //用户查询URL
            dataQueryUrlAccessor: function () {
                return "/api/CommonDataExport/Search";
            },

            //添加用户URL
            dataAddUrlAccessor: function () {
                this.NodeValue().ICreateId = $("#HiddenUserID").val();
                return "/api/SqlQuery/Post";
            },
            dataUpdateAccessor: function (key) { return "/api/SqlQuery/Put/" + key; },
            dataNodeSelect: function (id) {
                return "/api/SqlQuery/get/" + id;
            },

            dataDeleteAccessor: function (data) {
                var userIDs = "";
                var check = $("input:checked");  //得到所有被选中的checkbox
                check.each(function (i) {        //循环拼装被选中项的值
                    userIDs = userIDs + ',' + $(this).val();
                });
                //清除多余的分割号
                userIDs = dropRsplit(userIDs, ",");
                if (userIDs != "") {
                    return appendQueryString("/api/CommonDataExport/DeleteSQL", { ids: userIDs });
                } else
                    return "";

            },
            changeEnd: function (data, event) {
                //对话框保存的后置事件  
            }
			, initEd: function () {
			    //gird初始化的后置事件 信息

			},
			showDlgBefore: function () {
			    
			},
			showDetailEnd: function (data) {
			    
			    
    
			}


        };

        gdViewModel = new gridViewModel(options);


        gdViewModel.init();
        ko.applyBindings(gdViewModel);


        options.frmElement.validate({
            rules: {


                 txtbSSqlName: { maxlength: 50 }, txtbSSqlStr: { maxlength: 500 }, txtbICreateId: { digits: true }, txtbDCreate: { date: true }, txtbISort: { digits: true }



            },
            messages: {


                 txtbSSqlName: { maxlength: '最大长度为25' }, txtbSSqlStr: { maxlength: '最大长度为2000' }, txtbICreateId: { digits: '必须是整数' }, txtbDCreate: { date: '必须是日期格式，例如：2013/01/01' }, txtbISort: { digits: '必须是整数' }

            }
        });


    });

</script>






<!--/end grid code-->

